package fun.ticsmyc.dataStructure;

import java.util.LinkedHashMap;
import java.util.Map;

/**
 * @author Ticsmyc
 * @package fun.ticsmyc.dataStructure
 * @date 2020-03-11 21:49
 */
public class LRU extends LinkedHashMap {

    private final int threshold;
    public LRU(int maxSize){
        super(maxSize,0.75f,true);
        threshold=maxSize;
    }

    @Override
    protected boolean removeEldestEntry(Map.Entry eldest){
        return size()>threshold;
    }

    public static void main(String[] args) {
        LRU map = new LRU(3);
        map.put(1,1);
        map.put(2,2);
        map.put(3,3);
        System.out.println(map);
        map.get(2);
        map.put(4,4);
        System.out.println(map);
    }
}
